package weekend2;

import java.util.Random;
import java.util.Scanner;

public class Review {
    public static void main(String[] args) {
        Animal x=new Dog("1",2,"3");//向上造型，自动转换类型
        Swim s=(Swim)x;//强制转换类型

        /**
         * 需求:生成?位验证码(大写字母、小写字母、数字)
         */


        Scanner scan=new Scanner(System.in);
        String code=randCode(6);

        System.out.println("请输入验证码:"+code);

        /**
         * 需求:----------常见面试题
         *   找到2到100之间的所有素数(质数)
         *   素数:除了1和它本身外，不能被其它任何自然数整数的数
         */
        for(int i=2;i<=100;i++){
            Boolean flag=true;
            for(int j=2;j<=i/2;j++){

                if(i%j==0){
                    flag=false;
                }
            }
            if(flag){
                System.out.print(i+" ");
            }
        }
        System.out.println();

        Animal []animals=new Animal[3];
        animals[0]=new Dog("泡泡",8,"棕");
        animals[1]=new Cat("年年",2,"蓝");
        animals[2]=new Duck("丫丫",1,"白");
        for(int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            if(animals[i] instanceof Swim){
                Swim swim=(Swim)animals[i];
                swim.swim();
            }
            if(animals[i] instanceof LayEggs){
                LayEggs l=(LayEggs)animals[i];
                l.layEggs();
            }
            if(animals[i] instanceof LookHome){
                LookHome l=(LookHome)animals[i];
                l.lookHome();
            }
            if(animals[i] instanceof Cat){
                Cat cat=(Cat)animals[i];
                cat.lickHair();
            }
        }

    }

    public static String randCode(int num){
        Random rand=new Random();
        String code="";
        int index;
        char[] arr={'a','b','c','d','e','f','g','h','i','j','k',
                'l','m','n','o','p','q','r','s','t','u','v',
                'w','x','y','z','A','B','C','D','E','F','G',
                'H','I','J','K','L','M','N','O','P','Q','R',
                'S','T','U','V','W','X','Y','Z','0','1','2',
                '3','4','5','6','7','8','9'};
        for(int i=0;i<num;i++){
           index=rand.nextInt(61);
           code=code+arr[index];
        }

        return code;
    }




}
